import { Crypto, Base64} from './crypto.js'
import utils from '@/utils/utils.js'
export const aliOssParams = (oss_aid, oss_aky, expiration, oss_securityToken, oss_host) => {
  console.log(oss_aid, oss_aky, expiration, oss_securityToken, oss_host)

  if (!oss_aid || !oss_aky || !expiration || !oss_securityToken) {
    return false
  }
  var s_aid = oss_aid// 你自己的阿里云的accessid
  var s_aky = oss_aky// 你自己的阿里云的accesskey
  var policyText = {
    'expiration': expiration, // 上传的文件失效日期自己定义
    'conditions': [
        ['content-length-range', 0, 10485760000]// 上传的内容大小，自己定义
    ]
  }

  var policy = Base64.encode(JSON.stringify(policyText))// 生成的加密策略
	    var bytes = Crypto.util.HMAC(Crypto.util.SHA1, policy, s_aky, { asBytes: true })
	    var signature = Crypto.util.bytesToBase64(bytes)// 生成的签名
  var _fileName = utils.fileName('mp4')
  return {
    policy: policy,
    signature: signature,
    aid: s_aid,
	  securityToken: oss_securityToken,
	  fileName: _fileName,
	  host: oss_host
  }
}
